import './index.scss'
import { useSelector } from 'react-redux'
import type { RootState } from '../store/store'
import { useState } from 'react'


export default function () {

  const answerlist = useSelector((state: RootState) => state.questionnaire.answersId) || []
  const question = useSelector((state: RootState) => state.questionnaire.questions) || []
  const caculatescore = (): number => {
    let count = 0
    // 遍历用户的答案列表
    answerlist.forEach((selectedAnswerId: number) => {
      // 遍历所有问题
      question.forEach((questionItem: any) => {
        // 在每个问题的答案列表中查找匹配的答案
        questionItem.topic_answer.forEach((answer: any) => {
          if (selectedAnswerId === answer.topic_answer_id && answer.is_standard_answer === 1) {
            count++
            console.log(count);
            
          }
        })
      })
    })
    return count
  }

  return (
    <div className='result-containner'>
        <div className='result-containner-hd'>
          <div className='result-containner-hd-title'>
            测试结果
          </div>
        </div>
        <div className='result-containner-bd'>
          <div className='result-containner-bd-score'>
            得分：{caculatescore()*20}分
          </div>
          <div className='result-containner-bd-result'>
            你真是个小天才！
          </div>
        </div>
        <div className='result-containner-ft'>
          <div className='result-containner-ft-btn'>
            <i className='iconfont icon-shuaxin'></i>
            <p>再来一次</p> 
          </div>
        </div>
    </div>
  )
}
